package com.usian.skill.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.usian.skill.mapper.OrderInfoMapper;
import com.usian.skill.mapper.SkillOrderMapper;
import com.usian.skill.pojo.OrderInfo;
import com.usian.skill.pojo.SkillOrder;
import com.usian.skill.service.OrderInfoService;
import com.usian.skill.vo.GoodsVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

@Service
public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo> implements OrderInfoService {


    @Resource
    private SkillOrderMapper skillOrderMapper;

    @Override
    public OrderInfo addDingDan(String userId, GoodsVo goodsVo) {
        OrderInfo orderInfo=new OrderInfo();
        orderInfo.setUserId(Long.parseLong(userId));
        orderInfo.setStatus(0);
        orderInfo.setPayDate(null);
        orderInfo.setGoodsPrice(goodsVo.getMiaoshaPrice());
        orderInfo.setOrderChannel(1);
        orderInfo.setGoodsName(goodsVo.getGoodsName());
        orderInfo.setGoodsId(goodsVo.getId());
        orderInfo.setGoodsCount(1);
        orderInfo.setCreateDate(new Date());
        orderInfo.setDeliveryAddrId(1L);
        save(orderInfo);
        SkillOrder skillOrder=new SkillOrder();
        skillOrder.setUserId(Long.parseLong(userId));
        skillOrder.setOrderId(orderInfo.getId());
        skillOrder.setGoodsId(goodsVo.getId());
        skillOrderMapper.insert(skillOrder);
        return orderInfo;
    }
}
